import { onShow } from "@dcloudio/uni-app";
import { onMounted, ref } from "vue";
import {  myUserStore } from "../../../store";
import { goToPage, showModal } from "../../../utils/utils";
import { myAccountOverviewStore } from "../../store";
import { storeToRefs } from "pinia";

var statusBarHeight:number|undefined|0 =0;
// #ifdef  MP
statusBarHeight=uni.getSystemInfoSync().statusBarHeight
// #endif

export default{

    setup() {
        const userStore = myUserStore()
        const accountOverviewStore=myAccountOverviewStore();

        // 用户基本信息包括仪表盘数据
        const {myUser:userInfo} = storeToRefs(userStore);
        const {accountOverview } = storeToRefs(accountOverviewStore);

        onMounted(async () => {
            // 获取用户的基本数据和身份信息
            userStore.getMyUserInfo()
        })

        // 退出登录
        const typeShowModal = async () => {
            const status = await showModal({
                title: `退出登录`,
                content: `您确定要退出登录？`
            });
            if (status) {
                goToPage({
                    path: `/common/mainEnter/mainEnter`,
                    navType: `replaceAll`
                });
            }
        }
        // 组件被开启
        async function comOnShow(){
            accountOverviewStore.getMyAccountOverview()
        }
        // 组件被隐藏
        function comOnHide(){
        }

        function goToOtherPage(path:string){
            goToPage({
                path,
                navType: `push`
            });
        }
        return {
            accountOverview,
            statusBarHeight,
            userInfo,
            typeShowModal,
            goToOtherPage,
            comOnShow,
            comOnHide
        }
    }
}